//
//  LoginView.m
//  mendianjieke
//
//  Created by 响当当 on 8/1/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "LoginView.h"

@interface LoginView()<UITextFieldDelegate>
@property (nonatomic, strong)UIButton *areaButton;//区号
@property (nonatomic, strong)UITextField *phoneTextField;//手机号输入
@property (nonatomic, strong)UIView *lineView;//下划线
@property (nonatomic, strong)UIButton *sendMessageBtn;//获取短信验证码
@property (nonatomic, strong)NSString *phoneNum;//手机号码
@end

@implementation LoginView

- (UIButton *)areaButton
{
    if (!_areaButton)
    {
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(30*kUIScaleBasePlus,30*kUIScaleBasePlus,250*kUIScaleBasePlus,35*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentLeft
                                                   textClor:LCHexColor(0x282828)
                                                   textFont:25*kUIScaleBasePlus];
        titleLabel.text = @"欢迎登录导购专家";
        [self addSubview:titleLabel];
        
        _areaButton = [Utilties creatButtonWithFrame:CGRectMake(30*kUIScaleBasePlus,CGRectGetMaxY(titleLabel.frame)+64*kUIScaleBasePlus,28*kUIScaleBasePlus,21*kUIScaleBasePlus)
                                        textAligment:UIControlContentHorizontalAlignmentCenter
                                                text:@"+86"
                                            textClor:LCHexColor(0x282828)
                                           buttonBGC:[UIColor clearColor]
                                            textFont:13*kUIScaleBasePlus
                                              target:self
                                              method:@selector(areaButtonClcik)];
        
        UIImageView *rowImageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_areaButton.frame)+7*kUIScaleBasePlus,CGRectGetMaxY(titleLabel.frame)+70*kUIScaleBasePlus,10*kUIScaleBasePlus,10*kUIScaleBasePlus)];
        rowImageView.image = [UIImage imageNamed:@"maihu_xiangyou"];
        [self addSubview:rowImageView];
    }
    return _areaButton;
}

- (UITextField *)phoneTextField
{
    if (!_phoneTextField)
    {
        _phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.areaButton.frame)+30*kUIScaleBasePlus,self.areaButton.frame.origin.y,200*kUIScaleBasePlus,25*kUIScaleBasePlus)];
        _phoneTextField.delegate = self;
        _phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        [_phoneTextField becomeFirstResponder];
        [_phoneTextField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEvents];
    }
    return _phoneTextField;
}

- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(30*kUIScaleBasePlus,CGRectGetMaxY(self.phoneTextField.frame)+15*kUIScaleBasePlus,315*kUIScaleBasePlus,1*kUIScaleBasePlus)];
        _lineView.backgroundColor = JSALineColor;
        
        UIButton *chooseButton = [Utilties creatButtonWithFrame:CGRectMake(30*kUIScaleBasePlus,CGRectGetMaxY(_lineView.frame)+12*kUIScaleBasePlus,14*kUIScaleBasePlus,14*kUIScaleBasePlus)
                                                   textAligment:UIControlContentHorizontalAlignmentCenter
                                                           text:@""
                                                       textClor:LCHexColor(0xFFFFFF)
                                                      buttonBGC:[UIColor clearColor]
                                                       textFont:10*kUIScaleBasePlus
                                                         target:self
                                                         method:@selector(choosClick:)];
        chooseButton.selected = YES;
        [chooseButton setImage:[UIImage imageNamed:@"yixuan"] forState:UIControlStateSelected];
        [chooseButton setImage:[UIImage imageNamed:@"weixuan"] forState:UIControlStateNormal];
        [self addSubview:chooseButton];
        
        UILabel *subTitleLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(chooseButton.frame)+2*kUIScaleBasePlus,CGRectGetMaxY(_lineView.frame)+10*kUIScaleBasePlus,70*kUIScaleBasePlus,17*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentLeft
                                                      textClor:LCHexColor(0x8B8B8B)
                                                      textFont:10*kUIScaleBasePlus];
        subTitleLabel.text = @"已阅读并同意";
        [self addSubview:subTitleLabel];
        
        UIButton *customerCodingBtn = [Utilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(subTitleLabel.frame),CGRectGetMaxY(_lineView.frame)+7*kUIScaleBasePlus,100*kUIScaleBasePlus,17*kUIScaleBasePlus)
                                                        textAligment:UIControlContentHorizontalAlignmentLeft
                                                                text:@"《KWAY用户协议》"
                                                            textClor:LCHexColor(0xFF7A17)
                                                           buttonBGC:[UIColor clearColor]
                                                            textFont:10*kUIScaleBasePlus
                                                              target:self
                                                              method:@selector(customerClick)];
        [self addSubview:customerCodingBtn];
        [customerCodingBtn sizeToFit];
        
        UIButton *secretBtn = [Utilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(customerCodingBtn.frame),CGRectGetMaxY(_lineView.frame)+7*kUIScaleBasePlus,110*kUIScaleBasePlus,17*kUIScaleBasePlus)
                                                        textAligment:UIControlContentHorizontalAlignmentLeft
                                                                text:@"《KWAY用户隐私协议》"
                                                            textClor:LCHexColor(0xFF7A17)
                                                           buttonBGC:[UIColor clearColor]
                                                            textFont:10*kUIScaleBasePlus
                                                              target:self
                                                              method:@selector(secretClick)];
        [self addSubview:secretBtn];
        [secretBtn sizeToFit];
    }
    return _lineView;
}

- (UIButton *)sendMessageBtn
{
    if (!_sendMessageBtn)
    {
        _sendMessageBtn = [Utilties creatButtonWithFrame:CGRectMake(30*kUIScaleBasePlus,CGRectGetMaxY(self.lineView.frame)+72*kUIScaleBasePlus,315*kUIScaleBasePlus,40*kUIScaleBasePlus)
                                            textAligment:UIControlContentHorizontalAlignmentCenter
                                                    text:@"获取短信验证码"
                                                textClor:LCHexColor(0xFFFFFF)
                                               buttonBGC:LCHexColor(0xFF7A17)
                                                textFont:17*kUIScaleBasePlus
                                                  target:self
                                                  method:@selector(sendMessage:)];
        _sendMessageBtn.layer.masksToBounds = YES;
        _sendMessageBtn.layer.cornerRadius = _sendMessageBtn.frame.size.height/2;
        [self addSubview:_sendMessageBtn];
        
    }
    return _sendMessageBtn;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.areaButton];
        [self addSubview:self.phoneTextField];
        [self addSubview:self.lineView];
        [self addSubview:self.sendMessageBtn];
    }
    return self;
}

#pragma mark - Method
- (void)textChange:(UITextField *)textfield
{
    self.phoneNum = textfield.text;
}

- (void)areaButtonClcik
{
    
}

- (void)choosClick:(UIButton *)sender
{
    if (sender.selected)
    {
        sender.selected = NO;
        self.sendMessageBtn.enabled = NO;
        [self.sendMessageBtn setBackgroundColor:LCHexColor(0xFFBA87)];
    }
    else
    {
        sender.selected = YES;
        self.sendMessageBtn.enabled = YES;
        [self.sendMessageBtn setBackgroundColor:LCHexColor(0xFF7A17)];
    }
}

- (void)customerClick
{
    
}

- (void)secretClick
{
    
}

- (void)sendMessage:(UIButton *)sender
{
    [self.phoneTextField resignFirstResponder];
    
    if (![Utilties checkTel:self.phoneTextField.text])         return;
    
    if (self.changeViewBlock)
    {
        self.changeViewBlock(self.phoneNum);
    }
}
@end
